/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.model.ct;

import com.losenote.base.LnConstrant;
import com.losenote.enums.FileRelTypeEnum;
import com.losenote.enums.FileTypeEnum;
import com.losenote.model.AttachFile;
import com.losenote.orm.AttachFileDO;

/**
 * 文件转换器
 * 
 * @author danjingyu
 * @version $Id: AttachFileConvertor.java, v 0.1 2013-9-12 下午11:15:49 danjingyu Exp $
 */
public class AttachFileConvertor {

    /**
     * 对象转换
     * 
     * @param attachFileDo
     * @return
     */
    public static AttachFile fromDo(AttachFileDO attachFileDo, String basePath) {
        if (attachFileDo == null) {
            return null;
        }
        AttachFile attachFile = new AttachFile();
        attachFile.setFileName(attachFileDo.getName());
        attachFile.setFileType(FileTypeEnum.getByValue(attachFileDo.getType()));
        attachFile.setRelType(FileRelTypeEnum.getByValue(attachFileDo.getType()));
        attachFile.setGmtCreate(attachFileDo.getGmtCreate());
        attachFile.setId(attachFileDo.getId());
        attachFile.setUploader(attachFileDo.getName());
        attachFile.setFilePath(basePath + LnConstrant.FILE_SEPARTER
                               + attachFile.getRelType().getCode() + LnConstrant.FILE_SEPARTER
                               + attachFile.getFileType().getCode() + LnConstrant.FILE_SEPARTER
                               + attachFileDo.getName());
        return attachFile;
    }
}
